package com.project.collectAPI.entity.MeiTuan;

import com.google.gson.Gson;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;

import java.io.IOException;

public class MeituanDoWork {

    private static final String appId="";
    private static final String appSecret="";

    //批量接口请求地址 https://waimaiopen.meituan.com/api/v1/retail/batchinitdata
    private static final String apiUrl="https://waimaiopen.meituan.com/api/v1/retail/batchinitdata ";

    private static SystemParam systemParam = new SystemParam();

    public static void batchStart(){

        //设置请求参数
        Gson gson = new Gson();
        MeituanGoods meituanGoods=new MeituanGoods();
        meituanGoods.setApp_poi_code("123123");
        meituanGoods.setOperate_type(1);

        MeituanGoods.fooddata fooddata=new MeituanGoods.fooddata();
        fooddata.setApp_spu_code("1008");
        fooddata.setName("家用电吹风");
        String foods=gson.toJson(fooddata);

        //中间临时测试
       /* JSONObject jsonObject=JSONObject.parseObject(foods);
        System.out.println(jsonObject.get("name"));*/

        meituanGoods.setFood_data("["+foods+"]");
        String finalJson = gson.toJson(meituanGoods);
        System.out.println(finalJson);

        //发起请求
        try {
            HttpGet httpGet = new HttpGet(apiUrl);
            httpGet.setHeader("request-process-way", "asyn");
            CloseableHttpClient httpClient = HttpClients.createDefault();
            CloseableHttpResponse response = httpClient.execute(httpGet);
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }

    }

/*    private SystemParam systemParam = new SystemParam("应用的appId", "应用的appSecret");
    public void retailBatchinitdata() {
        //组建请求参数,如有其它参数请补充完整
        RetailBatchInitDataRequest retailBatchInitDataRequest = new RetailBatchInitDataRequest(systemParam);
        retailBatchInitDataRequest.setApp_poi_code("666");
        retailBatchInitDataRequest.setOperate_type(1);
        retailBatchInitDataRequest.setFood_data("[{\"app_spu_code\":\"1001\",\"box_num\":1,\"box_price\":0.5,\"category_name\":\"日用百货\",\"is_sold_out\":1,\"min_order_count\":1,\"name\":\"电吹风\",\"description\":\"静音效果非常好\",\"unit\":\"个\",\"picture\":\"2B86BE5A5C23786232DE37A4717E0D93,86BE5A5C23786232DE37A4712324535,22BE5A5C23786232DE37A47123243567,\",\"sequence\":1,\"price\":\"55\",\"tag_id\":\"200001291\",\"zh_id\":\"1002252\",\"product_name\":\"飞利浦多功率电吹风\",\"origin_name\":\"北京\",\"flavour\":\"可调节功率\",\"common_attr_value\":[{\"attrId\":100002441,\"attrName\":\"品牌\",\"valueList\":[{\"valueId\":1018448,\"value\":\"小西瓜\"}]},{\"attrId\":100002137,\"attrName\":\"产地\",\"valueList\":[{\"valueId\":130600,\"value\":\"保定\"}]},{\"attrId\":100002412,\"attrName\":\"普通属性\",\"valueList\":[{\"valueId\":100001545,\"value\":\"2\"}]},{\"attrId\":100002442,\"attrName\":\"大小\",\"valueList\":[{\"valueId\":100001574,\"value\":\"大\"},{\"valueId\":100001575,\"value\":\"中\"}]}],\"skus\":[{\"sku_id\":\"0101\",\"spec\":\"1000W\",\"upc\":\"6964472386689\",\"price\":\"55\",\"stock\":\"10\",\"available_times\":{\"monday\":\"09:00-09:30\",\"tuesday\":\"09:00-09:30,12:30-14:00\",\"wednesday\":\"00:00-00:00\",\"thursday\":\"15:00-23:00\",\"friday\":\"10:00-23:00\",\"saturday\":\"19:00-22:30\",\"sunday\":\"09:00-09:30,13:30-15:00,20:00-21:00\"},\"location_code\":\"23\",\"box_num\":\"1\",\"box_price\":\"0\",\"weight\":430,\"weight_for_unit\":\"430\",\"weight_unit\":\"克(g)\",\"openSaleAttrValueList\":[{\"attrId\":100002086,\"valueId\":100001190,\"value\":\"红\"},{\"attrId\":100002144,\"valueId\":100001263,\"value\":\"S\"}]}],\"picture_contents\":\"http://p0.meituan.net/xianfu/63d5cb4cf120c89da74c1dd3e7c8bae651375.jpg, A71E7F8D324B269F6557EE24799335A9\",\"properties\":[{\"property_name\":\"颜色\",\"values\":[\"粉色\",\"白色\"]}],\"is_specialty\":1,\"video_id\":124123,\"limit_sale_info\":\"{\\\"limitSale\\\":true,\\\"type\\\":3,\\\"begin\\\":\\\"20200209\\\",\\\"count\\\":30,\\\"end\\\":\\\"20200230\\\"}\"},{...}]");

        //发起请求
        SgOpenResponse sgOpenResponse;
        try {
            sgOpenResponse = retailBatchInitDataRequest.doRequest();
        } catch (SgOpenException e) {
            e.printStackTrace();
            return;
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }

        //发起请求时的sig，用来联系美团员工排查问题时使用
        String requestSig = sgOpenResponse.getRequestSig();
        //请求返回的结果，按照官网的接口文档自行解析即可
        String requestResult = sgOpenResponse.getRequestResult();
    }*/


}
